﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace Symbonix.NorSoNet.Security.BLL.Membership
{
    public class Education
    {
        public string InstituteName
        {
            get;
            set;
        }
        
        public int StartYear
        {
            get;
            set;
        }
        
        public int EndYear
        {
            get;
            set;
        }

        public List<string> Concentration
        {
            get;
            set;
        }

        public string Degree
        {
            get;
            set;
        }

        public Education()
        {
        }

        public Education(
            string instituteName,
            int startYear,
            int endYear,
            List<string> concentration,
            string degree)
        {
            InstituteName = instituteName;
            StartYear = startYear;
            EndYear = endYear;
            Concentration = concentration;
            Degree = degree;
        }


        public static string Serialize(List<Education> educations)
        {
            if (educations.Count == 0)
                return string.Empty;
            StringBuilder stringBuilder = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(stringBuilder);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Education>));
            xmlSerializer.Serialize(xmlWriter, educations);
            return stringBuilder.ToString();
        }

        public static List<Education> DeSerialize(string xml)
        {
            if (string.IsNullOrEmpty(xml))
                return new List<Education>();
            StringReader stringReader = new StringReader(xml);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Education>));
            return (List<Education>)xmlSerializer.Deserialize(stringReader);
        }
    }
}
